package part9.interpreter;

import part9.ast.AST;

import java.lang.reflect.Method;

public abstract class NodeVisitor {
    protected Object visit(AST node) throws Exception, IllegalAccessException {
        String[] strings = node.getClass().getName().split("\\.");
        String className = strings[strings.length-1];

        Method visitMethod = this.getClass().getDeclaredMethod("visit"+className, AST.class);
        return visitMethod.invoke(this, node);
    }
    protected void genericVisit() throws Exception {
        throw new Exception("No this type to visit");
    }
    abstract Object visitBinOp(AST node) throws Exception;
    abstract Object visitNum(AST node);
    abstract Object visitUnaryOp(AST node) throws Exception;
    abstract Object visitCompound(AST node) throws Exception;
    abstract Object visitAssign(AST node) throws Exception;
    abstract Object visitVar(AST node) throws Exception;
    abstract Object visitNoOp(AST node) throws Exception;
}
